<template>
  <div class="gray-page resident-detail-page">
    <nav-bar :title="title"></nav-bar>
    <div class="resident-detail-main page-main">
      <van-sticky class="page-scroll" :offset-top="44">
        <person-info></person-info>
        <van-form
          validate-trigger="onSubmit"
          :show-error="false"
          ref="from"
          input-align="right"
          error-message-align="right"
          :label-width="120"
          @failed="onFailed"
          @submit="onSubmit"
        >
          <van-field
            required
            readonly
            clickable
            name="idTypeName"
            v-model="formParams.idTypeName"
            label="人员标签"
            placeholder="请选择"
            right-icon="arrow"
            :rules="rules.idTypeName"
            @click="dictOpenPopup('idType')"
          />
        </van-form>
      </van-sticky>
    </div>
  </div>
</template>
<script>
import Upload from '@/mixins/upload'
import SelectPopup from '@/mixins/selectPopup'
import General from '@/api/general'
import Resident from '@/api/resident'
// import { FormParams } from './libs/personCare'
import { residentNameReg, idCardCheck, phoneReg, passPortCardReg, alphaNumber } from '@/libs/regexp'
import PersonInfo from '@/components/Widget/Resident/Collection/personInfo'
export default {
  mixins: [Upload, SelectPopup],
  components: { PersonInfo },
  data() {
    return {
      title: '关爱人员基础信息详情',
      activeNames: ['1', '2'],
      folder: 'approve/personCare',
      maxSize: 10 * 1024 * 1024,
      fileList: [],

      formParams: {}
    }
  },
  created() {
    // 更新
    if (this.$route.query.personCode) {
      this.title = '关爱人员基础信息更新'
      this.getDetail()
    }
  },
  methods: {
    // 获取详情
    getDetail() {
      Resident.BaseInfo.residentDetail({
        personCode: this.$route.query.personCode,
        baseType: this.$route.query.baseType
      }).then(res => {
        const { status, data } = res.data
        if (status === 0) {
          this.formParams = { ...data[0].personInfo, houseInfo: data[0].houseInfo }
          if (this.formParams.personImage) {
            this.fileList = [
              {
                url: this.formParams.personImage
              }
            ]
          }
        }
      })
    },
    onFailed(errorInfo) {
      this.$refs.from.scrollToField(errorInfo.errors[0].name)
    },
    // 表单 - 提交
    onSubmit() {
      // this.formParams.personImage = this.fileList[this.fileList.length - 1].url
      // if (!this.formParams.houseInfo.length) {
      //   this.$dialog.alert({
      //     title: '提示',
      //     message: '请绑定房屋信息'
      //   })
      //   return false
      // }
      // Resident.BaseInfo[this.$route.query.personCode ? 'residentUpdate' : 'residentSave'](this.formParams).then(res => {
      //   const { status } = res.data
      //   if (status === 0) {
      //     this.$toast.success('提交成功')
      //     this.$router.push('/resident/collection/message')
      //   } else {
      //     this.$toast.fail(res.data.message)
      //   }
      // })
    }
  }
}
</script>
